import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent } from '@delon/abc/table';
import { SFSchema, SFComponent } from '@delon/form';
import { HttpService, SupDic, GridComponent } from 'lbf';
import { NzMessageService } from 'ng-zorro-antd';
import { RepserviceService } from '@core/lb/repservice.service';

import { SafeResourceUrl, DomSanitizer } from '@angular/platform-browser';

@Component({
  selector: 'app-dzda-pzjfxx',
  templateUrl: './pzjfxx.component.html',
  styleUrls: ['./pzjfxx.component.less']
})
export class DzdaPzjfxxComponent implements OnInit {

  wjparam = {snames: {query: 'dzda_pzjfstcx'},param: {}}
  ifrmeee: SafeResourceUrl;
  repid: any;
  repmsg:any;

  isVisible = false;
  params = {sname: 'dzda_pzjfxxcx',queryparas: {}}
  searchSchema: SFSchema = {
    properties: {
      DAD017: {
        type: 'number',
        title: '事项编码',
        enum: this.supdic.getSFDic('DAD017'),
        ui: {
          widget: 'select',
          allowClear: true,
          width: 350
        }
      },
      // DAD028: {
      //   type: 'number',
      //   title: '凭证ID',
      //   enum: this.supdic.getSFDic('DAD028'),
      //   ui: {
      //     widget: 'select',
      //     allowClear: true,
      //     width: 200
      //   }
      // },
      // CAC045: {
      //   type: 'string',
      //   title: '是否通过',
      //   enum: this.supdic.getSFDic('CAC045'),
      //   ui: {
      //     widget: 'select',
      //     allowClear: true,
      //     width: 200
      //   }
      // }
      CAH003: {
        type:'string',
        title: '凭证类别',
        enum: this.supdic.getSFDic('DAH003'),
        ui: {
          widget: 'select',
          allowClear: true,
          width: 250
        }
      }
    }
  };

  columns: STColumn[] = [
    {title:'业务流水号',index: 'DAD069'},
    {title:'事项编码',index: 'DAD017',dic:'DAD017'},
    {title:'凭证编码',index:'DAH001',dic:'DAH001'},
    {title:'凭证类别',index:'DAH003',dic:'DAH003'},
    // { title: '事项编码',  index: 'DAD017'},// dic: 'DAD017'},
    // { title: '凭证ID',index: 'DAD028'},
    // { title: '受理对象',index: 'DAD036',dic: 'DAD036'},
    // { title: '证件号码',index: 'DAD070'},
    // { title: '是否通过',index: 'CAC045',dic: 'CAC045'},
    // { title: '收件份数',index: 'CZE010'},
    // { title: '收件人',index: 'AAD011'},
    // { title: '收件时间',index: 'AAE036'},
    // { title: '资料类型',index: 'DAD161',format: (item)=> '凭证'},
    {
      title: '操作区',
      buttons: [
        { text: '详情', click: (item: any) => this.show(item)}
      ]
    }
  ];

  @ViewChild('sf',{static: false}) sf: SFComponent;
  @ViewChild('xqsf',{static: false}) xqsf: SFComponent;
  @ViewChild('st',{static: false}) st: GridComponent;
  constructor(private httpservice: HttpService,
    private supdic: SupDic,
    private msgSrv: NzMessageService,
    private repservice: RepserviceService, // private modalService: BsModalService,
    private sanitizer: DomSanitizer,) { }

  ngOnInit() { }

  show(item){
    this.print(item);
    this.isVisible = true;
  }

  print(item){

    this.httpservice.lbservice('dzda_pzjfstcx',{DAH001: item.DAH001}).then(resdata => {
      if(resdata < 1){
        this.msgSrv.error(resdata.errmsg);
      }else{
        this.repid = resdata.REPID;
        this.repmsg =  JSON.parse(resdata.REPMSG);

        this.paint(this.repid,this.repmsg)
      }
    })

  }

  paint(repid:string,repmsg:{}){
    this.repservice.getRep(repid,repmsg).then(resdata => {
      if (resdata != null) {
        this.ifrmeee = this.sanitizer.bypassSecurityTrustResourceUrl(
          String(resdata),
        );
      } else {
        alert('不存在报表');
      }
    });
  }

  handleCancel(){
    this.isVisible = false;
  }

  query(){
    this.st.pi = 1;
    this.st.reload(this.sf.value);
  }

}
